<template>
  <div class="view">
    <keep-alive>
      <router-view class="animated" :key="key" v-if="$route.meta.keepAlive" />
    </keep-alive>
    <router-view v-if="!$route.meta.keepAlive" />
    <dialog-popup v-if="currentDialog.showDialog"></dialog-popup>
  </div>
</template>

<script>
import DialogPopup from "components/common/DialogPopup/Index";
import { mapGetters } from "vuex";
export default {
  data() {
    return {};
  },
  components: {
    DialogPopup,
  },
  computed: {
    ...mapGetters(["currentDialog"]),
    key() {
      return this.$route.meta.update
        ? this.$route.name + +new Date()
        : this.$route.name;
    },
  },
  watch: {},
  created() {
    if (!this.utils.seekStore("fn_local_user")) {
      //获取用户注册当天最后一秒时间戳
      let todayYear = new Date().getFullYear();
      let todayMonth = new Date().getMonth();
      let todayDay = new Date().getDate();
      let todayTime = new Date(
        todayYear,
        todayMonth,
        todayDay,
        "23",
        "59",
        "59"
      ).getTime(); //毫秒
      let userInfo = {
        userId: this.genID(5),
        todayTime, //注册当日最后时间戳  Date.now - todayTime 判断是否为新用户
        createTime: Date.now(), //注册时间
      };
      this.utils.setStore("fn_local_user", userInfo);
    }
  },
  mounted() {
    if (!sessionStorage.getItem("fn_disable_update")) {
      sessionStorage.setItem("fn_disable_update", true);
      this.$api.logger.user_analysis({ logType: 0 });
    }
  },
  methods: {
    // 生成随机ID
    genID(length) {
      return Math.random().toString().substr(3, length) + Date.now();
    },
  },
};
</script>

<style lang="scss" scoped>
.view {
  // overflow: hidden;
}
</style>
